import ACT from '../actionType'
import { connect } from 'react-redux'
import { ajax } from '../../utils/axios'

/**
 * 获取用户信息
 * @return {{types: *[], promise: (function(): AxiosPromise<any>)}}
 */
export function getUserInfo() {
  return {
    types: [ACT.USER_GET_SUCCESS],
    promise: () => ajax.get('/user?', {})
  }
}

export function getUserInfo2(data) {
  return {
    type: ACT.USER_CHANGE,
    payload: data
  }
}

/**
 * 取出数据和绑定方法
 */
export const userReduce = connect(
  //取出数据
  state => ({
    user: state.User
  }),
  //绑定方法
  {
    getUserInfo
  }
)
